package com.king.controller;

import com.king.model.common.RestResponse;
import com.king.model.dto.BorrowBooksDto;
import com.king.model.dto.BorrowBooksParams;
import com.king.model.common.PageParams;
import com.king.model.common.PageResult;
import com.king.service.BorrowBooksService;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author king
 */
@Slf4j
@RestController
@RequestMapping("borrowBooks")
public class BorrowBooksController {

    @Autowired
    private BorrowBooksService borrowBooksService;

    @GetMapping("/page")
    public PageResult<BorrowBooksDto> getBorrowBooks(BorrowBooksParams borrowBooksParams,PageParams pageParams){
        return  borrowBooksService.getBorrowBooks(borrowBooksParams,pageParams);
    }

    @PostMapping("/{bookId}/{userId}")
    public RestResponse<Boolean> borrowBook(@PathVariable("bookId") Integer bookId ,@PathVariable("userId") Integer userId){
        return borrowBooksService.borrow(bookId,userId);
    }


    @PutMapping("/{borrowId}")
    public RestResponse<Boolean> returnBook(@PathVariable("borrowId") Integer borrowId ){
        return borrowBooksService.returnBook(borrowId);
    }
}
